package ThreadPool.lagou.concurrent.completableFuture.demo01;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: 获取结果和触发计算
 * @date 2022/10/7 14:05
 */
public class CompletetableFutureAPIDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
        CompletableFuture<String> stringCompletableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "abc";
        });
        System.out.println(stringCompletableFuture.get(2,TimeUnit.SECONDS));
    }

}
